﻿using MediatR;
using Traceability.Commont.Domains.ScratchTheFat;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;
namespace U.Enterprise.Api.Applications.SalesWeighings
{
    public class WeighTheFatDelHandler:IRequestHandler<WeighTheFatDelCommond, Resqults>
    {

        private readonly IBateRepository<WeighTheFat> _WeighTheFat;

        public WeighTheFatDelHandler(IBateRepository<WeighTheFat> weighTheFat)
        {
            _WeighTheFat = weighTheFat;
        }

        public async Task<Resqults> Handle(WeighTheFatDelCommond request, CancellationToken cancellationToken)
        {
            var list = new Resqults() { Code = 0 };


            var query = _WeighTheFat.GetAll().FirstOrDefault(x => x.MyProperty == request.MyProperty);
            if (query != null) {

                query.State = 1;
            
                _WeighTheFat.Update(query);

                list.Code = 1;
            }



            return list;

        }
    }
}
